package com.example.chessbattleplatform.web.Sys_User.controller;


import com.example.chessbattleplatform.Pojo.Result.WebResult;
import com.example.chessbattleplatform.utils.JsonFileUtils;
import com.example.chessbattleplatform.web.Sys_User.Pojo.Vo.RegisterVo;
import com.example.chessbattleplatform.web.Sys_User.Pojo.dto.LoginEmailRequest;
import com.example.chessbattleplatform.web.Sys_User.Pojo.dto.LoginRequest;
import com.example.chessbattleplatform.web.Sys_User.Pojo.dto.RegisterRequest;
import com.example.chessbattleplatform.web.Sys_User.Service.impl.UserServiceInterface;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
// 下面 用户类 放行
public class UserController {
    private final UserServiceInterface userServiceInterface;

    // 登录端点
    @PostMapping("/loginUser")
    public WebResult<?> login(@Valid @RequestBody LoginRequest loginRequest) {
        return WebResult.success(userServiceInterface.loginUser(loginRequest));
    }

    // 登录端点
    @PostMapping("/loginEmail")
    public WebResult<?> loginUserEmail(@Valid @RequestBody LoginEmailRequest loginEmailRequest) {
        return WebResult.success(userServiceInterface.loginUserEmail(loginEmailRequest));
    }

    // 注册端点
    @PostMapping("/register")
    public WebResult<RegisterVo> register(@Valid @RequestBody RegisterRequest registerRequest) {
        JsonFileUtils.saveJsonToFile("注册端点", registerRequest);

        return WebResult.success(userServiceInterface.registerUser(registerRequest));

    }


}
